package com.xjm.bean.init;

import com.AnnotationContextDemo;
import com.xjm.controller.HelloController;
import com.xjm.model.Person;
import com.xjm.model.Root;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.Map;

/**
 * @author jaymin
 * 2020/11/28 18:19
 */
@Configuration
@ComponentScan(value = "com.xjm")
public class BeanDefinitionDemoByAnnotation {
	public static void main(String[] args) {
		ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AnnotationContextDemo.class);
		Person kobe = (Person) applicationContext.getBean("Kobe");
		Map<String, Person> beansOfType = applicationContext.getBeansOfType(Person.class);
		beansOfType.entrySet().stream().forEach(System.out::println);
		Person james = (Person) applicationContext.getBean("James");
		System.out.println(kobe.toString());
		System.out.println(james.toString());
		Root root = applicationContext.getBean("root", Root.class);
	}
}
